﻿using House.Server.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using House.Server.Common;
namespace House.Server.Repository
{
    /// <summary>
    /// 部门表DAL层
    /// </summary>
    public class System_DepartmentRepository : GenericBaseRepository<Department>
    {

        public List<System_DepartmentSelect> DepartmentShow(int id)
        {
            List<System_DepartmentSelect> list=new List<System_DepartmentSelect>();
            string sql=@"select *  from t_Department where D_del=@del";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    var p = cmd.CreateParameter();
                    p.ParameterName = "@del";
                    p.Value = id;
                    cmd.Parameters.Add(p);
                    var x = cmd.ExecuteReader();

                    try
                    {
                        while (x.Read())
                        {
                            System_DepartmentSelect Department=new Dto.System_DepartmentSelect();
                            Department.D_del=Convert.ToInt32(x["D_del"]);
                            Department.D_home=x["D_home"].ToString();
                            Department.D_id=Convert.ToInt32(x["D_id"]);
                            Department.D_iid=Convert.ToInt32(x["D_iid"]);
                            Department.D_name=x["D_name"].ToString();
                            Department.D_phone=x["D_name"].ToString();
                            Department.D_state=x["D_state"].ToString();
                            Department.D_status=Convert.ToInt32( x["D_status"]);
                            Department.D_time=Convert.ToDateTime(x["D_time"]);
                            Department.DepartmentState=EnumHelper.GetEnumSelectState<EnumStaffState>(Department.D_status);
                            list.Add(Department);
                        }
                    }
                    finally
                    {
                        x.Close();
                    }
                }
                return list;
            }

        }

    }
}
